package com.ruoyi.web.controller.system.fuw;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fuw.domain.FuwCollection;
import com.ruoyi.fuw.service.IFuwCollectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收藏Controller
 * 
 * @author ruoyi
 * @date 2021-10-09
 */
@RestController
@RequestMapping("/fuw/collection")
public class FuwCollectionController extends BaseController
{
    @Autowired
    private IFuwCollectionService fuwCollectionService;

    /**
     * 查询收藏列表
     */
    @PreAuthorize("@ss.hasPermi('fuw:collection:list')")
    @GetMapping("/list")
    public TableDataInfo list(FuwCollection fuwCollection)
    {
        startPage();
        List<FuwCollection> list = fuwCollectionService.selectFuwCollectionList(fuwCollection);
        return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @PreAuthorize("@ss.hasPermi('fuw:collection:export')")
    @Log(title = "收藏", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FuwCollection fuwCollection)
    {
        List<FuwCollection> list = fuwCollectionService.selectFuwCollectionList(fuwCollection);
        ExcelUtil<FuwCollection> util = new ExcelUtil<FuwCollection>(FuwCollection.class);
        return util.exportExcel(list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('fuw:collection:query')")
    @GetMapping(value = "/{uId}")
    public AjaxResult getInfo(@PathVariable("uId") Long uId)
    {
        return AjaxResult.success(fuwCollectionService.selectFuwCollectionByUId(uId));
    }

    /**
     * 新增收藏
     */
    @PreAuthorize("@ss.hasPermi('fuw:collection:add')")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FuwCollection fuwCollection)
    {
        return toAjax(fuwCollectionService.insertFuwCollection(fuwCollection));
    }

    /**
     * 修改收藏
     */
    @PreAuthorize("@ss.hasPermi('fuw:collection:edit')")
    @Log(title = "收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FuwCollection fuwCollection)
    {
        return toAjax(fuwCollectionService.updateFuwCollection(fuwCollection));
    }

    /**
     * 删除收藏
     */
    @PreAuthorize("@ss.hasPermi('fuw:collection:remove')")
    @Log(title = "收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uIds}")
    public AjaxResult remove(@PathVariable Long[] uIds)
    {
        return toAjax(fuwCollectionService.deleteFuwCollectionByUIds(uIds));
    }
}
